﻿using System;

namespace LinqBridge.InternalHelpers
{
	/// <summary>
	/// Helper class providing conversion methods dependent on the runtime
	/// version (fix for early mono runtimes)
	/// </summary>
	static class ConversionHelper
	{
		/// <summary>
		/// Converts string to DateTimeOffset.
		/// </summary>
		public static DateTimeOffset? ToDateTimeOffset(string value)
		{
			return impl.ToDateTimeOffset(value);
		}

		/// <summary>
		/// Converts string to TimeSpan
		/// </summary>
		public static TimeSpan ToTimeSpanHelper(string s)
		{
			return impl.ToTimeSpanHelper(s);
		}

		/// <summary>
		/// Converts string to float
		/// </summary>
		public static float ToSingle(string s)
		{
			return impl.ToSingle(s);
		}

		/// <summary>
		/// Converts string to double
		/// </summary>
		public static double ToDouble(string s)
		{
			return impl.ToDouble(s);
		}

		private static readonly IConversion impl
			=  (Type.GetType("Mono.Runtime") != null)
				? (IConversion)new MonoConversion()
				: new NetConversion();
	}
}